//
//  RW_UserSingleAddView.m
//  SleepApp
//
//  Created by chuangqi on 2021/4/9.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_UserSingleAddView.h"
#import "RW_UserSingleViewModel.h"
@interface RW_UserSingleAddView ()
/** 取消 */
@property (nonatomic,strong) UIButton *wlclass_close_button;
/** 确定 */
@property (nonatomic,strong) UIButton *wlclass_sure_button;

/** VM */
@property (nonatomic,strong) RW_UserSingleViewModel *wlclass_user_single_view_model;
@end

@implementation RW_UserSingleAddView
#pragma mark -- 视图初始化 必须实现
/** 初始化视图数据 */
-(void)initView{
    self.backgroundColor = UIColor.whiteColor;


    self.layer.shadowOpacity = 0.2f;
    self.layer.shadowRadius = 5.f;
    self.layer.shadowOffset = CGSizeMake(0,0);
    self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.3f].CGColor;
    self.layer.cornerRadius = 8;
    self.clipsToBounds = YES;
    
    [self.contentView addSubview:self.wlclass_title_label];
    [self.contentView addSubview:self.wlclass_text_field];
    [self.contentView addSubview:self.wlclass_close_button];
    [self.contentView addSubview:self.wlclass_sure_button];
    
    [self.wlclass_title_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).mas_offset(15);
    }];
    [self.wlclass_text_field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.contentView).mas_offset(20);
        make.right.mas_equalTo(self.contentView).mas_offset(-20);
        make.height.mas_offset(50);
    }];
    [self.wlclass_close_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(self.contentView);
        make.height.mas_offset(45);
    }];
    [self.wlclass_sure_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.wlclass_close_button.mas_right);
        make.width.mas_equalTo(self.wlclass_close_button);
        make.height.mas_equalTo(self.wlclass_close_button);
    }];
}
/** 初始化视图数据 */
-(void)initData:(NSArray *)dataList{
    self.wlclass_title_label.text = @"新建歌单";
}
#pragma mark -- Base代理
/**
 可选
 视图弹出方向
 */
-(Base_General_Show_type)showViewLocation{
    return Base_General_Show_type_Botton;
}
/**
 可选
 判断是否展示弹窗
 需要展示 则调用isShowBlock()回调
 默认展示
 */
-(void)isShowModelList:(NSArray<id> *)dataList isShowBlock:(void(^)(void))isShowBlock{
    isShowBlock();
}
/**
 可选
 是否需要处理点击确定后的操作逻辑
 点击确认按钮的 选中数据操作。
 需要子试图调用 defaultSureCloseViewData: 方法
 会回调 closeBlock_wl 的block块，内容为操作完毕后的内容
 默认回调 closeBlock_wl，无参数
 */
-(void)clickSelectCloseViewData:(id)data sureBlock:(void(^)(id data))sureBlock{
    NSString *titleString = data;
    [SVProgressHUD showMask_wl];
    NSLog(@"%@",titleString);
    [self.wlclass_user_single_view_model addSUserSingleName:titleString success:^(NSString * _Nonnull response) {
        [SVProgressHUD showSuccess_wl:@"添加成功"];
        if (sureBlock){
            sureBlock(response);
        }
    } fail:^(NSError * _Nonnull error) {
        [SVProgressHUD showError_wl:@"操作失败"];
    }];
}

/**
 可选
 初始化展示视图约束
 默认的大小为屏幕高度一半，底部贴合
 */
-(void)initViewMakeConstraints:(MASConstraintMaker *)make fromView:(UIView *)fromView{
    make.center.mas_equalTo(fromView);
    make.height.mas_offset(170);
    make.width.mas_equalTo(fromView).multipliedBy(.8f);
}
///**
// 可选
// 自定显示动画方式
// 参考内部实现方式
// */
//-(void)showView:(BaseGeneralView *)view fromView:(UIView *)fromView{
//    self.transform = CGAffineTransformMakeTranslation(0,fromView.frame.size.height);
//    [UIView animateWithDuration:0.4f animations:^{
//        self.transform = CGAffineTransformIdentity;
//        self.alpha = 1.f;
//    } completion:^(BOOL finished) {
//        [UIView animateWithDuration:0.2f animations:^{
//            self.transform = CGAffineTransformMakeTranslation(0,5);
//
//        }];
//    }];
//}

#pragma mark -- 操作
-(void)click_sure_button:(UIButton *)sender{
    if (!self.wlclass_text_field.text.length){
        [SVProgressHUD showError_wl:@"名称长度不能为空"];
        return;
    }
    if (self.wlclass_text_field.text.length > 10){
        [SVProgressHUD showError_wl:@"不能超过十个字符"];
        return;
    }
    [self defaultSureCloseViewData:self.wlclass_text_field.text];
}



#pragma mark -- 懒加载
-(UITextField *)wlclass_text_field{
    if (!_wlclass_text_field){
        _wlclass_text_field = [[UITextField alloc]init];
        _wlclass_text_field.placeholder = @"歌单名称";
        _wlclass_text_field.textAlignment = NSTextAlignmentCenter;
    }
    return _wlclass_text_field;
}
-(UIButton *)wlclass_sure_button{
    if (!_wlclass_sure_button){
        _wlclass_sure_button = [[UIButton alloc]init];
        [_wlclass_sure_button setTitle:@"确定" forState:UIControlStateNormal];
        [_wlclass_sure_button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        [_wlclass_sure_button addTarget:self action:@selector(click_sure_button:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _wlclass_sure_button;
}
-(UIButton *)wlclass_close_button{
    if (!_wlclass_close_button){
        _wlclass_close_button = [[UIButton alloc]init];
        [_wlclass_close_button setTitle:@"取消" forState:UIControlStateNormal];
        [_wlclass_close_button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        [_wlclass_close_button addTarget:self action:@selector(defaultCloseView) forControlEvents:UIControlEventTouchUpInside];
    }
    return _wlclass_close_button;
}
-(UILabel *)wlclass_title_label{
    if (!_wlclass_title_label){
        _wlclass_title_label = [[UILabel alloc]init];
    }
    return _wlclass_title_label;
}
-(RW_UserSingleViewModel *)wlclass_user_single_view_model{
    if (!_wlclass_user_single_view_model){
        _wlclass_user_single_view_model = [[RW_UserSingleViewModel alloc]init];
    }
    return _wlclass_user_single_view_model;
}
@end
